package com.schoolgard.entitybean;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "ROLE")
@SequenceGenerator (name="AUTO_ID", sequenceName="AUTO_ID")
public class Role implements java.io.Serializable {

	private static final long serialVersionUID = 201202251307L;

	private Long id;
	private String name;
	private Boolean enable;
	private Set<RolePrivilege> rolePrivileges = new HashSet<RolePrivilege>(0);
	/*private Set<RoleOfUsers> roleToUserses = new HashSet<RoleOfUsers>(0);*/

	// Constructors

	/** default constructor */
	public Role() {
	}

	/** minimal constructor */
	public Role(Long id) {
		this.id = id;
	}

	/** full constructor 
	public Role(Long id, String name, Boolean enable,
			Set<RolePrivilege> rolePrivileges, Set<RoleOfUsers> roleToUserses) {
		this.id = id;
		this.name = name;
		this.enable = enable;
		this.rolePrivileges = rolePrivileges;
		this.roleToUserses = roleToUserses;
	}
*/
	// Property accessors
	@Id
	@Column(name = "ID", unique = true, nullable = false, precision = 10, scale = 0)
	@GeneratedValue (strategy=GenerationType.SEQUENCE, generator="AUTO_ID")
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "NAME", length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "ENABLE", precision = 1, scale = 0)
	public Boolean getEnable() {
		return this.enable;
	}

	public void setEnable(Boolean enable) {
		this.enable = enable;
	}

	@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER, mappedBy = "role")
	public Set<RolePrivilege> getRolePrivileges() {
		return this.rolePrivileges;
	}

	public void setRolePrivileges(Set<RolePrivilege> rolePrivileges) {
		this.rolePrivileges = rolePrivileges;
	}

	/*@OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, mappedBy = "role" )
	public Set<RoleOfUsers> getRoleToUserses() {
		return this.roleToUserses;
	}

	public void setRoleToUserses(Set<RoleOfUsers> roleToUserses) {
		this.roleToUserses = roleToUserses;
	}
	*/

}